package com.easy.web.service.impl;

import com.easy.web.mapper.ArticleTypeMapper;
import com.easy.web.model.ArticleType;
import com.easy.web.model.ArticleTypeExample;
import com.easy.web.service.ArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/1/5.
 */
@Service
@Transactional
public class ArticleTypeServiceImpl implements ArticleTypeService {

    @Autowired
    private ArticleTypeMapper articleTypeMapper;
    /**
     * 查询所有文章类型
     */
    @Override
//    @Cacheable(value = "ArticleType",key = "0")
    public List<ArticleType> getArticleTypeList() {
        ArticleTypeExample articleTypeExample=new ArticleTypeExample();
        articleTypeExample.setOrderByClause("seq");
        return articleTypeMapper.selectByExample(articleTypeExample);
    }

    /**
     * 根据id查询类型信息
     *
     * @param id
     */
    @Override
//    @Cacheable(value = "ArticleType",key = "#id")
    public ArticleType queryArticleTypeById(String id) {
        return articleTypeMapper.selectByPrimaryKey(id);
    }

    /**
     * 根据名称查询类型信息
     *
     * @param name
     */
    @Override
    public ArticleType queryArticleTypeByName(String name) {
        ArticleTypeExample articleTypeExample=new ArticleTypeExample();
        articleTypeExample.createCriteria().andCommentEqualTo(name);
        List<ArticleType> articleTypeList=articleTypeMapper.selectByExample(articleTypeExample);
        if(articleTypeList.size()>0){
            return articleTypeList.get(0);
        }
        return null;
    }
}
